using System;
using System.Collections.Generic;

class App
{
	static Gdk.Point pt = new Gdk.Point(50, 50);

	public static void Main()
	{
		Gtk.Application.Init();

		Gtk.Dialog dlg = new Gtk.Dialog();
		dlg.SetSizeRequest(500, 400);
		dlg.ExposeEvent += new Gtk.ExposeEventHandler(dlg_ExposeEvent);
		dlg.Run();
	}

	static void dlg_ExposeEvent(object o, Gtk.ExposeEventArgs args)
	{
		Gdk.Drawable dr = args.Event.Window;
		Gdk.GC gc = new Gdk.GC(dr);

		Gdk.Point[] points = new Gdk.Point[]
		{
			new Gdk.Point(20,20),
			new Gdk.Point(100,10),
			new Gdk.Point(70,100),
			new Gdk.Point(50,40),
			new Gdk.Point(40,40),
			new Gdk.Point(30,100),
			new Gdk.Point(30,100),
		};

		Dida.Polygon2D pol = new Dida.Polygon2D(GdkPointToVector2D(points));

		pol.PointInPolygon(new Dida.Vector2D(25, 16));

		for (int y = 0; y < 300; y++)
		{
			for (int x = 0; x < 300; x++)
			{
				if (pol.PointInPolygon(new Dida.Vector2D(x, y)))
					gc.RgbFgColor = new Gdk.Color(255, 0, 0);
				else
					gc.RgbFgColor = new Gdk.Color(0, 255, 0);
				dr.DrawPoint(gc, x, y);
			}
		}

		gc.RgbFgColor = new Gdk.Color(0, 0, 0);
		dr.DrawPolygon(gc, false, points);
	}

	public static IEnumerable<Dida.Vector2D> GdkPointToVector2D(Gdk.Point[] pts)
	{
		foreach (Gdk.Point pt in pts)
		{
			yield return new Dida.Vector2D(pt.X, pt.Y);
		}
	}
}